import type { LoginResult, sendPhoneCodeResult } from '@/types/member'
import { http_login, http_data_results_not_list, http_object } from '@/utils/http'

type LoginWxMinParams = {
  code: string
  encryptedData?: string
  iv?: string
}
/**
 * 小程序登录
 * @param data 请求参数
 */
export const postLoginWxMinAPI = (data: LoginWxMinParams) => {
  return http_login<LoginResult>({
    method: 'POST',
    url: '/login/wxMin',
    data,
  })
}

/**
 * 小程序登录_内测版
 * @param phoneNumber 模拟手机号码
 */
export const postLoginWxMinSimpleAPI = (phoneNumber: string) => {
  return http_login<LoginResult>({
    method: 'POST',
    url: '/login/wxMin/simple',
    data: {
      phoneNumber,
    },
  })
}

type LoginParams = {
  username: string
  password: string
}
/**
 * 传统登录-用户名+密码
 * @param data 请求参数
 */
export const postLoginAPI = (data: LoginParams) => {
  console.log('postLoginAPI收到：', data)
  return http_data_results_not_list<LoginResult>({
    method: 'POST',
    url: '/WXLoginView/',
    data,
  })
}
type SigninParams = {
  phoneNumber: string
  inviter: string
  phoneCode: string
  real_name: string
}
/**
 * 传统登录-用户名+密码
 * @param data 请求参数
 */
export const postSigninAPI = (data: SigninParams) => {
  return http_login<LoginResult>({
    method: 'POST',
    url: '/RegisterView/',
    data,
  })
}
type sendPhoneCodeParams = {
  phoneNumber: string
}
/**
 * 发送手机短信验证码
 * @param data 请求参数
 */
export const sendPhoneCodeAPI = (data: sendPhoneCodeParams) => {
  console.log('sendPhoneCodeAPI收到参数', data)
  return http_object<sendPhoneCodeResult>({
    method: 'GET',
    url: '/WXSendCodeView/',
    data,
  })
}
